<?php


class Tweet
{
	public $content;
	public $link;
	public $date;
	public $twit;
	public $twit_link;
	public $twit_pic;
	public $twit_uid;
	
	public function __construct( $content, $link, $date, $twit, $twit_link, $twit_pic )
	{
		$this->content = $content;
		$this->link = $link;
//		$this->set_tweet_date();
		$this->date = $date;
		$this->twit = $twit;
		$this->twit_link = $twit_link;
		$this->twit_pic = $twit_pic;
		$this->set_twit_uid();
	}
	
	protected function set_twit_uid()
	{
		$twit_uid = str_replace( 'http://twitter.com/', '', $this->twit_link );
		$this->twit_uid = $twit_uid;
	}
	
	/**
	 *
	 */
	public function time_since()
	{
		// ARGH!! I give up on trying to calculate relative time strings!!
		return '';
	}
	
	public function time() 
	{
		$currentTime = time();
		$offset = date("Z", $currentTime);

		$matches = array();

		// Check to see if we're dealing with a UTC dateTime (ends in 'Z')
		// or if there's an offset specified (ends in '[+-]hh:mm’).
		if(preg_match("/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})([+-])(\d{2}):(\d{2})$/",
			$this->date, $matches) === 1) {
			// Offset specified.

			// Calculate the custom offset.
			$customOffset = $matches[3] * 60 * 60;
			$customOffset += $matches[4] * 60;

			// Invert the custom offset as necessary.
			if($matches[2] == "+") {
				$customOffset = -1 * $customOffset;
			}

			// Add the custom offset to the UTC offset to get the offset
			// from the local timezone.
			$offset += $customOffset;
		} else if (preg_match("/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})Z$/",
		$this->date, $matches) === 1) {
			// Using the UTC timezone.
		}

		$dateString = $matches[1];

		// Parse the date and time portion of the string.

		$datetimeArray = strptime($dateString, "%Y-%m-%dT%H:%M:%S");

		// Generate the UNIX time. Note that this will be in the wrong timezone.
		$time = mktime(
				$datetimeArray['tm_hour'],
				$datetimeArray['tm_min'],
				$datetimeArray['tm_sec'],
				$datetimeArray['tm_mon'] + 1,
				$datetimeArray['tm_mday'],
				$datetimeArray['tm_year'] + 1900
			);

		// Return the calculated UNIX time from above along with the offset
		// necessary to correct for the timezone specified.
		return $time + $offset;
	}
	

}


?>